package com.ruoyi.zxjd.conference.controller;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.zxjd.conference.domain.ConferenceArrange;
import com.ruoyi.zxjd.conference.domain.ConferenceProgress;
import com.ruoyi.zxjd.conference.service.IConferenceArrangeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zxjd.conference.domain.ConferenceParticipant;
import com.ruoyi.zxjd.conference.service.IConferenceParticipantService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 参会名单Controller
 * 
 * @author lcc
 * @date 2021-02-07
 */
@Controller
@RequestMapping("/conference/participant")
public class ConferenceParticipantController extends BaseController
{
    private String prefix = "conference/participant";

    @Autowired
    private IConferenceParticipantService conferenceParticipantService;

    @Autowired
    private IConferenceArrangeService conferenceArrangeService;

    @RequiresPermissions("conference:participant:view")
    @GetMapping()
    public String participant()
    {
        return prefix + "/participant";
    }

    /**
     * 查询参会名单列表
     */
    @RequiresPermissions("conference:participant:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ConferenceParticipant conferenceParticipant)
    {
        startPage();
        List<ConferenceParticipant> list = conferenceParticipantService.selectConferenceParticipantList(conferenceParticipant);
        return getDataTable(list);
    }

    /**
     * 导出参会名单列表
     */
    @RequiresPermissions("conference:participant:export")
    @Log(title = "参会名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ConferenceParticipant conferenceParticipant)
    {
        List<ConferenceParticipant> list = conferenceParticipantService.selectConferenceParticipantList(conferenceParticipant);
        ExcelUtil<ConferenceParticipant> util = new ExcelUtil<ConferenceParticipant>(ConferenceParticipant.class);
        return util.exportExcel(list, "participant");
    }

    /**
     * 新增参会名单
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        ConferenceArrange conferenceArrange = new ConferenceArrange();
        conferenceArrange.setStatus("1");
        List<ConferenceArrange> conferenceArranges = conferenceArrangeService.selectConferenceArrangeList(conferenceArrange);
        mmap.put("conferenceArranges",conferenceArranges);
        return prefix + "/add";
    }

    /**
     * 新增保存参会名单
     */
    @RequiresPermissions("conference:participant:add")
    @Log(title = "参会名单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ConferenceProgress conferenceProgress)
    {
        return toAjax(conferenceParticipantService.insertConferenceParticipant(conferenceProgress));
    }

    /**
     * 新增保存参会单个人员
     */
    @RequiresPermissions("conference:participant:add")
    @Log(title = "参会名单", businessType = BusinessType.INSERT)
    @PostMapping("/addOne")
    @ResponseBody
    public AjaxResult addSave(ConferenceParticipant conferenceParticipant)
    {
        conferenceParticipant.setProgressId(0L);
        return toAjax(conferenceParticipantService.insertConferenceParticipantOne(conferenceParticipant));
    }

    /**
     * 修改参会名单
     */
    @GetMapping("/edit/{participantId}")
    public String edit(@PathVariable("participantId") Long participantId, ModelMap mmap)
    {
        ConferenceParticipant conferenceParticipant = conferenceParticipantService.selectConferenceParticipantById(participantId);
        mmap.put("conferenceParticipant", conferenceParticipant);
        return prefix + "/edit";
    }

    /**
     * 修改保存参会名单
     */
    @RequiresPermissions("conference:participant:edit")
    @Log(title = "参会名单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ConferenceParticipant conferenceParticipant)
    {
        return toAjax(conferenceParticipantService.updateConferenceParticipant(conferenceParticipant));
    }

    /**
     * 删除参会名单
     */
    @RequiresPermissions("conference:participant:remove")
    @Log(title = "参会名单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(conferenceParticipantService.deleteConferenceParticipantByIds(ids));
    }
}
